//
//  ViewController.m
//  Test
//
//  Created by Bob Wu on 2017/7/28.
//  Copyright © 2017年 bupterambition. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UIView *testView;

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) UITableViewCell *firstCell;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)testInvocation:(NSUInteger)index {
    NSLog(@"%ld",index);
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

#pragma mark - tableview datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 30;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 1) {
        return self.firstCell;
    }
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    UITableViewCell *view = cell;
    view.layer.shadowColor = UIColor.blackColor.CGColor;
    view.layer.shadowOffset = CGSizeMake(0, 0);
    view.layer.shadowOpacity = 0.9;
    cell.clipsToBounds = NO;
    return cell;
}


#pragma mark - Accessor

- (UIView *)testView {
    if (!_testView) {
        _testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
        _testView.clipsToBounds = YES;
        _testView.tag = 99;
        _testView.backgroundColor = [UIColor greenColor];
        [_testView addSubview:({
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -10, 210, 210)];
            view.layer.backgroundColor = [UIColor whiteColor].CGColor;
            view.layer.shadowOffset = CGSizeMake(0,0);
            UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(view.bounds,-5,-5) cornerRadius:4];
            [UIColor.greenColor setStroke];
            [bezierPath stroke];
            view.layer.shadowOpacity = 1;
            view.layer.shadowColor = [UIColor redColor].CGColor;
            view.layer.shadowPath = bezierPath.CGPath;
            view;
        })];
        
    }
    return _testView;
}

- (UITableView *)tableView {
	if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.clipsToBounds = YES;
	}
	return _tableView;
}

- (UITableViewCell *)firstCell {
	if (!_firstCell) {
        _firstCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
        _firstCell.layer.shadowColor = UIColor.redColor.CGColor;
        _firstCell.layer.shadowOffset = CGSizeMake(0, 0);
        _firstCell.layer.shadowOpacity = 0.9;
        _firstCell.clipsToBounds = YES;
        [_firstCell insertSubview:self.testView atIndex:0];
	}
	return _firstCell;
}
@end
